package com.mswork.mes.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.mswork.common.annotation.Log;
import com.mswork.common.core.controller.BaseController;
import com.mswork.common.core.domain.AjaxResult;
import com.mswork.common.enums.BusinessType;
import com.mswork.mes.domain.ProjectCargo;
import com.mswork.mes.service.IProjectCargoService;
import com.mswork.common.utils.poi.ExcelUtil;
import com.mswork.common.core.page.TableDataInfo;

/**
 * 货物Controller
 *
 * @author ruoyi
 * @date 2025-03-06
 */
@RestController
@RequestMapping("/mes/projectCargo")
public class ProjectCargoController extends BaseController
{
    @Autowired
    private IProjectCargoService projectCargoService;

    /**
     * 查询货物列表
     */
    @PreAuthorize("@ss.hasPermi('mes:projectCargo:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProjectCargo projectCargo)
    {
        startPage();
        List<ProjectCargo> list = projectCargoService.selectProjectCargoList(projectCargo);
        return getDataTable(list);
    }

    /**
     * 导出货物列表
     */
    @PreAuthorize("@ss.hasPermi('mes:projectCargo:export')")
    @Log(title = "货物", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProjectCargo projectCargo)
    {
        List<ProjectCargo> list = projectCargoService.selectProjectCargoList(projectCargo);
        ExcelUtil<ProjectCargo> util = new ExcelUtil<ProjectCargo>(ProjectCargo.class);
        util.exportExcel(response, list, "货物数据");
    }

    /**
     * 获取货物详细信息
     */
    @PreAuthorize("@ss.hasPermi('mes:projectCargo:query')")
    @GetMapping(value = "/{cargoId}")
    public AjaxResult getInfo(@PathVariable("cargoId") Long cargoId)
    {
        return success(projectCargoService.selectProjectCargoByCargoId(cargoId));
    }

    /**
     * 新增货物
     */
    @PreAuthorize("@ss.hasPermi('mes:projectCargo:add')")
    @Log(title = "货物", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProjectCargo projectCargo)
    {
        return toAjax(projectCargoService.insertProjectCargo(projectCargo));
    }

    /**
     * 修改货物
     */
    @PreAuthorize("@ss.hasPermi('mes:projectCargo:edit')")
    @Log(title = "货物", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProjectCargo projectCargo)
    {
        return toAjax(projectCargoService.updateProjectCargo(projectCargo));
    }

    /**
     * 删除货物
     */
    @PreAuthorize("@ss.hasPermi('mes:projectCargo:remove')")
    @Log(title = "货物", businessType = BusinessType.DELETE)
    @DeleteMapping("/{cargoIds}")
    public AjaxResult remove(@PathVariable Long[] cargoIds)
    {
        return toAjax(projectCargoService.deleteProjectCargoByCargoIds(cargoIds));
    }
}
